package org.management.utils;

import org.slf4j.LoggerFactory;

/**
 * 功能描述
 *
 * @author jy
 * @date 2019/3/29
 * @description
 * @project management
 */
public class LoggerUtils {

    public static void error(String msg) {
        LoggerFactory.getLogger(getClassName()).error(getMessage(msg));
    }

    public static void error(Class clazz, String msg) {
        LoggerFactory.getLogger(clazz).error(getMessage(msg));
    }

    public static void error(String msg, Object... obj) {
        LoggerFactory.getLogger(getClassName()).error(getMessage(msg), obj);
    }

    public static void warn(String msg) {
        LoggerFactory.getLogger(getClassName()).error(getMessage(msg));
    }

    public static void warn(Class clazz, String msg) {
        LoggerFactory.getLogger(clazz).warn(getMessage(msg));
    }

    public static void warn(String msg, Object... obj) {
        LoggerFactory.getLogger(getClassName()).error(getMessage(msg), obj);
    }

    public static void info(String msg) {
        LoggerFactory.getLogger(getClassName()).info(getMessage(msg));
    }

    public static void info(Class clazz, String msg) {
        LoggerFactory.getLogger(clazz).info(getMessage(msg));
    }

    public static void info(String msg, Object... obj) {
        LoggerFactory.getLogger(getClassName()).info(getMessage(msg), obj);
    }

    public static void debug(String msg) {
        LoggerFactory.getLogger(getClassName()).debug(getMessage(msg));
    }

    public static void debug(Class clazz, String msg) {
        LoggerFactory.getLogger(clazz).debug(getMessage(msg));
    }

    public static void debug(String msg, Object... obj) {
        LoggerFactory.getLogger(getClassName()).debug(getMessage(msg), obj);
    }


    private static StackTraceElement getStackTraceElement() {
        StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
        return stacktrace[stacktrace.length - 1];
    }

    private static Class getClassName(){
        return getStackTraceElement().getClass();
    }

    private static String getMessage(String message){
       StackTraceElement element = getStackTraceElement();
       return "\n\n**************"+
                "\n打印文件名："+element.getFileName() +
                "\n打印类名："+ element.getClassName() +
                "\n方法名：" + element.getMethodName() +
                "\n行号：" + element.getLineNumber() +
                "\n打印内容: "+ message +
                "\n**************\n\n";

    }

}
